﻿@{
    var listUser = ViewData["listUser"] as List<KimPhongCRM.Models.sp_Select_Combobox_User_Result>;
    var grid = Html.DevExpress().GridView(settings =>
    {
        settings.Name = "ListLichSuLoaiThe";
        settings.CallbackRouteValues = new { Controller = "LichSuLoaiThe", Action = "ListLichSuLoaiThePartial" };

        settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "LichSuLoaiThe", Action = "ListLichSuLoaiThePartialAddNew" };
        settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "LichSuLoaiThe", Action = "ListLichSuLoaiThePartialUpdate" };
        settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "LichSuLoaiThe", Action = "ListLichSuLoaiThePartialDelete" };
        settings.SettingsEditing.Mode = GridViewEditingMode.EditFormAndDisplayRow;
        settings.SettingsBehavior.ConfirmDelete = true;
        settings.CommandColumn.ButtonType = System.Web.UI.WebControls.ButtonType.Image;
        settings.CommandColumn.SetColVisibleIndex(6);
        settings.CommandColumn.SetHeaderCaptionTemplateContent("Tùy chọn");
        settings.CommandColumn.Width = 100;

        settings.CommandColumn.NewButton.Image.Url = @Url.Content("~/Content/img/icon-24-new.png");
        settings.CommandColumn.NewButton.Image.ToolTip = "Thêm mới";
        settings.CommandColumn.NewButton.Image.AlternateText = "Thêm";

        settings.CommandColumn.EditButton.Visible = true;
        settings.CommandColumn.EditButton.Image.Url = @Url.Content("~/Content/img/icon-24-edit.png");
        settings.CommandColumn.EditButton.Image.ToolTip = "Thay đổi";
        settings.CommandColumn.EditButton.Image.AlternateText = "Sửa";

        settings.CommandColumn.DeleteButton.Visible = true;
        settings.CommandColumn.DeleteButton.Image.Url = @Url.Content("~/Content/img/icon-24-delete.png");
        settings.CommandColumn.DeleteButton.Image.ToolTip = "Xóa";
        settings.CommandColumn.DeleteButton.Image.AlternateText = "Xóa";

        settings.CommandColumn.UpdateButton.Visible = true;
        settings.CommandColumn.UpdateButton.Image.Url = @Url.Content("~/Content/img/icon-24-ok.png");
        settings.CommandColumn.UpdateButton.Image.ToolTip = "Lưu lại";
        settings.CommandColumn.UpdateButton.Image.AlternateText = "Lưu";

        settings.CommandColumn.CancelButton.Visible = true;
        settings.CommandColumn.CancelButton.Image.Url = @Url.Content("~/Content/img/icon-24-cancel.png");
        settings.CommandColumn.CancelButton.Image.ToolTip = "Hủy";
        settings.CommandColumn.CancelButton.Image.AlternateText = "Hủy";

        settings.CommandColumn.Visible = true;
        settings.CommandColumn.DeleteButton.Visible = true;
        settings.CommandColumn.EditButton.Visible = true;

        settings.KeyFieldName = "maLichSu";

        settings.SettingsPager.Visible = true;
        settings.Settings.ShowGroupPanel = true;
        settings.Settings.ShowFilterRow = true;
        settings.SettingsBehavior.AllowSelectByRowClick = true;

        settings.Columns.Add(column =>
        {
            column.FieldName = "maLichSu";
            column.Caption = "Mã LS";
            column.ColumnType = MVCxGridViewColumnType.TextBox;
            column.FixedStyle = GridViewColumnFixedStyle.Left;
            column.Visible = false;
            column.Width = 100;
        });
        settings.Columns.Add(column =>
        {
            column.FieldName = "nguoiSua";
            column.Caption = "Người sửa";
            column.ColumnType = MVCxGridViewColumnType.ComboBox;
            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
            foreach (var value in listUser)
            {
                comboBoxProperties.Items.Add(value.UserName, value.UserId);
            }
            comboBoxProperties.ValueType = typeof(Guid);
            column.ReadOnly = true;
            column.Width = 100;
        });
        settings.Columns.Add(column =>
        {
            column.FieldName = "ngaySua";
            column.Caption = "Ngày sửa";
            column.ColumnType = MVCxGridViewColumnType.DateEdit;
            var dateProperties = column.PropertiesEdit as DateEditProperties;
            dateProperties.UseMaskBehavior = true;
            dateProperties.EditFormat = EditFormat.Custom;
            dateProperties.EditFormatString = "dd/MM/yyyy hh:mm tt";
            column.ReadOnly = true;
            column.Width = 100;
        });

        settings.Columns.Add(column =>
        {
            column.FieldName = "loaiSuaDoi";
            column.Caption = "Loại sửa đổi";
            column.ColumnType = MVCxGridViewColumnType.ComboBox;
            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
            comboBoxProperties.Items.Add("Xóa", -1);
            comboBoxProperties.Items.Add("Cập nhật", 0);
            comboBoxProperties.Items.Add("Thêm mới", 1);
            column.SetDataItemTemplateContent(c =>
            {

                int edittyppe = Convert.ToInt32(DataBinder.Eval(c.DataItem, "loaiSuaDoi"));
                if (edittyppe == -1)
                {
                    ViewContext.Writer.Write(
                       "<i style=\"color: #FA603D;\" class=\"font-icon-remove-sign\"></i> " + c.Text
                   );
                }
                else if (edittyppe == 1)
                {
                    ViewContext.Writer.Write(
                       "<i style=\"color: #78CD51;\" class=\"font-icon-plus-sign \"></i> " + c.Text
                   );
                }
                else
                {
                    ViewContext.Writer.Write(
                       "<i style=\"color: #FABB3D;\" class=\"font-icon-ok-sign \"></i> " + c.Text
                   );
                }
            });
            comboBoxProperties.ValueType = typeof(int);
            column.ReadOnly = true;
            column.Width = 100;
        });

        settings.Columns.Add(column =>
        {
            column.FieldName = "noiDung";
            column.Caption = "Nội dung";
            column.ColumnType = MVCxGridViewColumnType.TextBox;
            column.ReadOnly = true;
        });
    });
    if (ViewData["EditError"] != null)
    {
        grid.SetEditErrorText((string)ViewData["EditError"]);
    }
}
@grid.Bind(Model).GetHtml()